---
title: Run a prompt with tools
description: Learn how to run a prompt with tools using the Latitude SDK
---

## Prompt

In this example, we define a tool to get the weather. How you obtain the weather is up to you—you might call a third-party service or something within your own system. Once you have the weather information, you return the response to the LLM, and it finishes processing the prompt with that data. You can read more about [tool calling here](/guides/prompt-manager/tools).

<CodeGroup>
```markdown example
---
provider: Latitude
model: gpt-4o-mini
tools:
  - get_weather:
      description: Gets the weather temperature from a given location.
      parameters:
        type: object
        additionalProperties: false
        required: ['location']
        properties:
          location:
            type: string
            description: Name of the location
---

What should I wear for the weather in {{ location }}?
```
</CodeGroup>

## Code

When calling a tool, you can process the data using the arguments your users provide and return a response.

<CodeGroup>
````typescript Typescript
import { Latitude } from '@latitude-data/sdk'

// You can type the tools you are using
type Tools = { get_weather: { location: string } }

async function run() {
  const sdk = new Latitude(process.env.LATITUDE_API_KEY, {
    projectId: Number(process.env.PROJECT_ID),
    versionUuid: 'live',
  })

  const response = await sdk.prompts.run<Tools>(
    'run-prompt-with-tools/example',
    {
      parameters: { location: 'Boston' },
      tools: {
        get_weather: async ({ location }) => {
          return { temperature: `2°C for ${location}` }
        },
      },
    },
  )

  console.log('RESPONSE', JSON.stringify(response, null, 2))
}

run()
````
````python Python
import asyncio
import os
from typing import Any

from devtools import pprint
from latitude_sdk import (
    ApiError,
    FinishedResult,
    Latitude,
    LatitudeOptions,
    OnToolCallDetails,
    RunPromptOptions,
    StreamEvent,
)


async def get_weather(arguments: dict[str, Any], details: OnToolCallDetails) -> str:
    pprint(details)

    # Simulate a call to a weather API
    return "2°C"


async def on_event(event: StreamEvent):
    print(event, "\n" * 2)


async def on_finished(result: FinishedResult):
    print(result, "\n" * 2)


async def on_error(error: ApiError):
    print(error, "\n" * 2)


async def run():
    api_key = os.getenv("LATITUDE_API_KEY")
    sdk_options = LatitudeOptions(
        project_id=int(os.getenv("PROJECT_ID")),
        version_uuid="live",
    )

    sdk = Latitude(api_key, sdk_options)
    result = await sdk.prompts.run(
        "run-prompt-with-tools/example",
        RunPromptOptions(
            parameters={
                "location": "Boston",
            },
            tools={"get_weather": get_weather},
            on_event=on_event,
            on_finished=on_finished,
            on_error=on_error,
            stream=True,
        ),
    )

    if result:
        print(result.response.text, "\n" * 2)


asyncio.run(run())
````
</CodeGroup>
